﻿using System.Windows.Forms;

namespace Oryon.Extensions.Windows
{
    /// <summary>
    /// Common extension methods for Windows Forms
    /// </summary>
    public static class Functions
    {
        /// <summary>
        /// Find any control instance from it' s name in parent control
        /// </summary>
        /// <param name="parentControl">Container control something like that Form or Panel etc...</param>
        /// <param name="searchingControlName">Searching control' s name</param>
        /// <returns>if succedded it returns control' s instance</returns>
        public static Control FindMyControl(this Control parentControl,string searchingControlName)
        {
            foreach (Control currentControl in parentControl.Controls)
            {
                if (currentControl.Name.ToUpper() == searchingControlName.ToUpper())
                    return currentControl;

                Control childControl = FindMyControl(currentControl, searchingControlName);
                if (childControl != null)   
                    return childControl;
            }
            return null;
        }
    }
}
